<template>
  <div class="app-container">
    <div class="head">
      <img src="@/assets/img/Layout/position.png" />
      <p class="see-block">产品集合</p>
    </div>
    <div class="view-container">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            class="btn-success"
            type="primary"
            icon="el-icon-plus"
            size="mini"
            @click="add()"
            v-hasPermi="['system:commodityCollection:insert']"
          >新建产品集合</el-button>
        </el-col>
      </el-row>
      <el-table :data="dataList" border>
        <el-table-column label="序号" type="index" align="center" width="50">
           <template slot-scope="scope">
            <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
          </template>
        </el-table-column>
        <el-table-column label="集合名称" align="center" prop="sortName" />
        <el-table-column label="产品数量" align="center" prop="productNum" />
        <el-table-column label="排序" align="center" prop="orderNum" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['system:commodityCollection:update']"
            >编辑</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['system:commodityCollection:deleteById']"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { proCollectionList, proCollectionDel } from "@/api/system/basedata/productCollection/productCollection"

export default {
  name: "list",
  data() {
    return {
      // 总条数
      total: 0,
      // 下发列表数据
      dataList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取列表
    getList() {
      proCollectionList(this.addDateRange(this.queryParams)).then(res => {
          this.dataList = res.rows
          this.total = res.total
      })
    },
    // 新建
    add(){
      this.$router.push({path:"/basedata/product/productCollection/add"})
    },
    // 编辑
    handleUpdate(row){
      this.$router.push({path:"/basedata/product/productCollection/edit", query:{ id: row.id }})
    },
    // 删除
    handleDelete(row){
      this.$modal.confirm('是否确认删除？').then(() => {
        proCollectionDel(row.id).then(() => {
          this.getList()
          this.$modal.msgSuccess("删除成功!")
        }).catch(() => {})
      })
    },
  }
}
</script>